package com.iknow.ui.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.iknow.IKnow;
import com.iknow.data.Word;
import com.iknow.db.IKnowDataBase;
import com.iknow.util.StringUtil;
import com.iknow.view.widget.TranslatePanel;
import java.util.ArrayList;
import java.util.List;

public class TheWordsAdapter extends BaseExpandableListAdapter
{
  private int childCount;
  public Context ctx = null;
  private ExpandableListView eListView = null;
  public List<String> gList;
  private int groupCount;
  private View.OnClickListener itemClick;
  private boolean mBShowCrashBox;
  protected LayoutInflater mLayoutInflater = null;
  public OnWordGroupRemoveCallBack mOnWordGroupRemoveCallBack;
  public OnWordRemoveCallback mOnWordRemoveCallback;
  private AdapterView.OnItemLongClickListener onGroupLongClickListener;
  private View.OnClickListener stateItemClick;
  protected TranslatePanel translatePanel = null;

  public TheWordsAdapter(Context paramContext, ExpandableListView paramExpandableListView)
  {
    this.mBShowCrashBox = true;
    this.mOnWordRemoveCallback = null;
    this.mOnWordGroupRemoveCallBack = null;
    this.gList = null;
    this.groupCount = -1;
    this.childCount = -1;
    this.stateItemClick = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (this.this$0.mOnWordRemoveCallback != null)
        {
          Word localWord = (Word)paramView.getTag();
          ArrayList localArrayList = new ArrayList();
          localArrayList.add(localWord);
          this.this$0.mOnWordRemoveCallback.fireOnWordRemoved(localArrayList);
        }
      }
    };
    this.onGroupLongClickListener = new AdapterView.OnItemLongClickListener(this)
    {
      public boolean onItemLongClick(, View paramView, int paramInt, long paramLong)
      {
        if (this.this$0.mOnWordGroupRemoveCallBack != null)
        {
          String str = (String)paramView.getTag();
          TheWordsAdapter.access$0(this.this$0).setTag(str);
          this.this$0.mOnWordGroupRemoveCallBack.removeWordGroup(str);
          this.this$0.gList.remove(str);
        }
        return true;
      }
    };
    this.itemClick = new View.OnClickListener(this)
    {
      public void onClick()
      {
        String str = ((TheWordsAdapter.ViewHolder)paramView.getTag()).key.getText().toString();
        if (this.this$0.translatePanel == null)
          this.this$0.translatePanel = new TranslatePanel(this.this$0.ctx);
        this.this$0.translatePanel.setDisplay(str);
        this.this$0.translatePanel.setMyFavoriteActivity(this.this$0.ctx);
      }
    };
    this.ctx = paramContext;
    this.eListView = paramExpandableListView;
    this.mLayoutInflater = ((LayoutInflater)paramContext.getSystemService("layout_inflater"));
    this.gList = new ArrayList();
  }

  protected void bindChildView(View paramView, Word paramWord)
  {
    if (paramWord == null);
    while (true)
    {
      ViewHolder localViewHolder;
      do
      {
        return;
        localViewHolder = (ViewHolder)paramView.getTag();
        localViewHolder.key.setText(paramWord.getKey());
        localViewHolder.lang.setText(paramWord.getLang());
        localViewHolder.def.setText(paramWord.getDef());
      }
      while (!(this.mBShowCrashBox));
      localViewHolder.state.setTag(paramWord);
    }
  }

  protected View createChildView()
  {
    ViewHolder localViewHolder = new ViewHolder(this);
    View localView = this.mLayoutInflater.inflate(2130903070, null);
    localViewHolder.key = ((TextView)localView.findViewById(2131296379));
    localViewHolder.lang = ((TextView)localView.findViewById(2131296382));
    localViewHolder.def = ((TextView)localView.findViewById(2131296380));
    localViewHolder.state = ((ImageButton)localView.findViewById(2131296381));
    if (this.mBShowCrashBox)
      localViewHolder.state.setOnClickListener(this.stateItemClick);
    while (true)
    {
      localView.setTag(localViewHolder);
      localView.setOnClickListener(this.itemClick);
      return localView;
      localViewHolder.state.setVisibility(8);
    }
  }

  public Object getChild(int paramInt1, int paramInt2)
  {
    return IKnow.mIKnowDataBase.getWord((String)this.gList.get(paramInt1), paramInt2);
  }

  public long getChildId(int paramInt1, int paramInt2)
  {
    return paramInt2;
  }

  public View getChildView(int paramInt1, int paramInt2, boolean paramBoolean, View paramView, ViewGroup paramViewGroup)
  {
    return getView(paramInt1, paramInt2, paramView, paramViewGroup);
  }

  public int getChildrenCount(int paramInt)
  {
    int i;
    if (this.gList.isEmpty())
      i = 0;
    while (true)
    {
      return i;
      this.childCount = IKnow.mIKnowDataBase.getWordCountByDate((String)this.gList.get(paramInt));
      if (this.childCount == 0)
        this.gList.remove(paramInt);
      i = this.childCount;
    }
  }

  public Object getGroup(int paramInt)
  {
    String str = IKnow.mIKnowDataBase.getWordDate(paramInt);
    this.gList.add(str);
    return str;
  }

  public int getGroupCount()
  {
    if (this.groupCount < 0)
      this.groupCount = IKnow.mIKnowDataBase.getWordDateCount();
    return this.groupCount;
  }

  public long getGroupId(int paramInt)
  {
    return paramInt;
  }

  public View getGroupView(int paramInt, boolean paramBoolean, View paramView, ViewGroup paramViewGroup)
  {
    String str;
    Object localObject;
    if ((this.gList != null) && (this.gList.size() == this.groupCount))
    {
      str = (String)this.gList.get(paramInt);
      if (!(StringUtil.isEmpty(str)))
        break label65;
      localObject = paramView;
    }
    while (true)
    {
      while (true)
      {
        return localObject;
        str = (String)getGroup(paramInt);
      }
      label65: localObject = getGroupViewStub(str);
    }
  }

  protected LinearLayout getGroupViewStub(String paramString)
  {
    AbsListView.LayoutParams localLayoutParams = new AbsListView.LayoutParams(-1, -2);
    LinearLayout localLinearLayout = new LinearLayout(this.ctx);
    localLinearLayout.setLayoutParams(localLayoutParams);
    TextView localTextView = new TextView(this.ctx);
    localTextView.setGravity(17);
    localTextView.setBackgroundResource(2130837575);
    localTextView.setText(paramString);
    localTextView.setTextColor(-1);
    localLinearLayout.addView(localTextView);
    localLinearLayout.setTag(paramString);
    this.eListView.setOnItemLongClickListener(this.onGroupLongClickListener);
    return localLinearLayout;
  }

  protected View getView(int paramInt1, int paramInt2, View paramView, ViewGroup paramViewGroup)
  {
    View localView;
    Word localWord = (Word)getChild(paramInt1, paramInt2);
    if (localWord == null)
      localView = null;
    while (true)
    {
      return localView;
      if (paramView == null)
        paramView = createChildView();
      bindChildView(paramView, localWord);
      localView = paramView;
    }
  }

  public boolean hasStableIds()
  {
    return false;
  }

  public void init()
  {
    this.groupCount = -1;
    this.childCount = -1;
  }

  public boolean isChildSelectable(int paramInt1, int paramInt2)
  {
    return true;
  }

  public void setBShowCrashBox(boolean paramBoolean)
  {
    this.mBShowCrashBox = paramBoolean;
  }

  public void setOnWordGroupRemoveCallBack(OnWordGroupRemoveCallBack paramOnWordGroupRemoveCallBack)
  {
    this.mOnWordGroupRemoveCallBack = paramOnWordGroupRemoveCallBack;
  }

  public void setOnWordRemoveCallback(OnWordRemoveCallback paramOnWordRemoveCallback)
  {
    this.mOnWordRemoveCallback = paramOnWordRemoveCallback;
  }

  public static abstract interface OnWordGroupRemoveCallBack
  {
    public abstract void removeWordGroup(String paramString);
  }

  public static abstract interface OnWordRemoveCallback
  {
    public abstract void fireOnWordRemoved(List<Word> paramList);
  }

  public class ViewHolder
  {
    TextView def;
    TextView key;
    TextView lang;
    ImageButton state;
  }
}